<template>
  <el-form ref="form" :rules="rules" label-width="100px">
    <el-form-item label="步骤名称" prop="name">
      <el-input v-model="step.name" placeholder="Key字段"></el-input>
    </el-form-item>
    <el-form-item label="Key字段">
      <el-input v-model="step.typefield" placeholder="Key字段"></el-input>
    </el-form-item>
    <el-button type="primary" @click="fetchFieldsFromTable">获取字段</el-button>
    <el-button icon="plus" @click="_addRecord"></el-button>
    <br><br>
    <el-table :data="step.fields" stripe>
      <el-table-column type="index" width="60"></el-table-column>
      <el-table-column label="字段名称" width="120">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.name}}</div>
          <div v-else>
            <el-select v-model="scope.row.name">
              <el-option v-for="item in step.availableFields" :value="item.name"></el-option>
            </el-select>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="key值" width="120">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.value}}</div>
          <div v-else>
            <el-input  v-model="scope.row.value"></el-input>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="value字段" width="120">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.norm}}</div>
          <div v-else>
            <el-input v-model="scope.row.norm" ></el-input>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="140" :max-height="300">
        <template scope="scope">
          <el-row>
            <el-col :span="12"><el-button size="small" type="info" @click="reverseEditState(scope.$index, scope.row)">编辑</el-button></el-col>
            <el-col :span="12"><el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button></el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
  </el-form>
</template>
<script>
  import {Steps,Fields} from "../../model/DataModel";
  import StepCommon from "./mixins/StepMixin";

  /**
   * 行转列step 无输出字段
   * */
  export default{
    mixins: [StepCommon],
    data(){
      return {
        step:Steps.Normaliser()
      }
    },
    methods:{
      fetchFieldsFromTable(){
          this.step.fields=this.step.availableFields.map(el=>Fields.Normaliser({name:el.name}))
      }
    }
  }
</script>
